//
//  YYECourseCollectionTableViewCell.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/4.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYECourseCollectionTableViewCell.h"

@interface YYECourseCollectionTableViewCell ()

@property (nonatomic,strong) UIImageView *headerIV;
@property (nonatomic,strong) UILabel *courseNameLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *numLabel;
@property (nonatomic,strong) UILabel *priceLabel;
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UIView *lineView;

@end

@implementation YYECourseCollectionTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.headerIV = [[UIImageView alloc]init];
        [self.contentView addSubview:self.headerIV];
        
        self.timeLabel = [[UILabel alloc]init];
        self.timeLabel.font = [UIFont systemFontOfSize:14];
        self.timeLabel.textColor = LineColor;
        self.timeLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.timeLabel];
        
        self.courseNameLabel = [[UILabel alloc]init];
        self.courseNameLabel.textColor = [UIColor blackColor];
        self.courseNameLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.courseNameLabel];
        
        self.numLabel = [[UILabel alloc]init];
        self.numLabel.textColor = LineColor;
        self.numLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.numLabel];
        
        self.priceLabel = [[UILabel alloc]init];
        self.priceLabel.textColor = GeneralRedColor;
        self.priceLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.priceLabel];
        self.priceLabel.hidden = YES;
        
        self.nameLabel = [[UILabel alloc]init];
        self.nameLabel.textColor = GeneralGrayColor;
        self.nameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.nameLabel];
        
        self.lineView = [[UIView alloc]init];
        self.lineView.backgroundColor = LightLineColor;
        [self.contentView addSubview:self.lineView];
        
        self.courseNameLabel.text = @"英语轻松过四级小";
        self.timeLabel.text = @"2017 12-29";
        self.numLabel.text = @"课时29";
        self.priceLabel.text = @"￥299";
        self.nameLabel.text = @"程晨";
        
    }
    return self;
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.headerIV makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(5);
        make.top.equalTo(self.contentView.top).offset(10);
        make.bottom.equalTo(self.contentView.bottom).offset(-10);
        make.size.equalTo(CGSizeMake(WSCALE * 109,WSCALE * 60 ));
    }];
    
    [self.courseNameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerIV.right).offset(10);
        make.right.equalTo(self.timeLabel.left).offset(-15);
        make.top.equalTo(self.contentView.top).offset(WSCALE * 20);
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right).offset(-15);
        make.centerY.equalTo(self.courseNameLabel.centerY);
    }];
    
    [self.numLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headerIV.right).offset(10);
        make.bottom.equalTo(self.contentView.bottom).offset(-WSCALE * 20);
    }];
    
    [self.priceLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.numLabel.right).offset(6);
        make.bottom.equalTo(self.contentView.bottom).offset(-WSCALE * 20);
    }];
    
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right).offset(-15);
        make.bottom.equalTo(self.contentView.bottom).offset(-WSCALE * 20);
    }];
    
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(15);
        make.right.equalTo(self.contentView.right).offset(-15);
        make.bottom.equalTo(self.contentView.bottom);
        make.height.equalTo(0.5);
    }];
    
}

- (void)setModel:(YYECourseCollModel *)model {
    _model = model;
    
    [self.headerIV sd_setImageWithURL:[NSURL URLWithString:model.img]];
    self.courseNameLabel.text = model.title;
    self.timeLabel.text = model.create_time;
    self.numLabel.text = [NSString stringWithFormat:@"课时%@",model.nums];
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];
    self.nameLabel.text = model.name;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
